package com.hy.main.draw;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class ShapeListener implements MouseListener { //重写监听器中的方法
    Graphics gr;

    @Override
    public void mouseClicked(MouseEvent e) {
        int x = e.getX();
        int y = e.getY();
        System.out.println("点击 x=" + x + " y=" + y);
    }

    int x1;
    int y1;
    //点击
    @Override
    public void mousePressed(MouseEvent e) {
        x1 = e.getX();
        y1 = e.getY();//随意按下一个点 然后获取它的坐标
        System.out.println("按下" + x1 + "=x1 y1=" + y1);
    }

    //按压
    @Override
    public void mouseReleased(MouseEvent e) {
        int x2 = e.getX();
        int y2 = e.getY();   //松开时通过鼠标监听器 获取坐标
        System.out.println("释放" + x2 + "=x2 y2=" + y2);//释放
        // 绘制直线
        gr.drawLine(x1, y1, x2, y2);  //两点确定一条直线
    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
